package com.copa.l1290;

/**
 * @author copa
 * @createDate 2022-09-05 10:13
 * @function 遍历法
 */
public class Test1 {

    public int getDecimalValue(ListNode head) {
        StringBuilder sb = new StringBuilder();
        while (head != null) {
            sb.append(head.val);
            head = head.next;
        }
        String s = sb.toString();
        int result = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            if ('1' == s.charAt(i)) {
                result += Math.pow(2, s.length() - i - 1);
            }
        }
        return result;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(0);
        head.next.next = new ListNode(0);
        System.out.println(new Test1().getDecimalValue(head));
    }
}
